function getUserInfo(pageName){
    $.ajax({
        url:"login",
        type:"get",
        success:function(user){
            if(user.id && user.id > 0){
                //展示用户信息
                showUserInfo(pageName);
                showCountInfo(pageName);
            }else{
                //跳转到登录界面
                location.assign("index.html");
            }
        }
    });
}

function showUserInfo(pageName){
    var url;
    if(pageName=="detail"){
        url = "user"+location.search;
    }else{
        url = "user";
    }
    $.ajax({
        type:"get",
        url:url,
        success:function(user){
            console.log(user);
            document.querySelector(".left .card h3").innerHTML = user.userName;
            document.querySelector(".left .card a").href = user.githubUrl;
            //如果登录用户和作者是同一个人，添加删除链接
            if(user.isYourBlog && user.isYourBlog == 1){
                var nav = document.querySelector(".nav");
                var a = document.createElement("a");
                a.className = "nav-span";
                a.innerHTML = "删除博客";
                a.href = "delete" + location.search;
                nav.insertBefore(a,nav.children[5]);
            }
        }
    });
}

function showCountInfo(pageName){
    var url;
    if(pageName=="detail"){
        url = "count"+location.search;
    }else{
        url = "count";
    }
    $.ajax({
        type:"get",
        url:url,
        success:function(count){
            console.log(count);
            document.querySelector(".left .card .row .num").innerHTML = count;
        }
    });
}